package edu.hitwh.controller;

import edu.hitwh.record.BorrowerRecord;
import edu.hitwh.record.LibrarianRecord;
import edu.hitwh.service.RegisterService;
import edu.hitwh.wrapper.Resp;
import io.github.resilience4j.bulkhead.annotation.Bulkhead;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.github.resilience4j.ratelimiter.annotation.RateLimiter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/register")
@RequiredArgsConstructor
@RateLimiter(name = "default-ratelimiter")
@Bulkhead(name = "default-bulkhead")
@CircuitBreaker(name = "default-circuitbreaker")
public class RegisterController {
    private final RegisterService registerService;

    @PostMapping("/librarian")
    public Resp<Boolean> registerLibrarian(@RequestBody LibrarianRecord librarianRecord) {
        registerService.registerLibrarian(librarianRecord.toEntity());
        return Resp.success(true);
    }

    @PostMapping("/borrower")
    public Resp<Boolean> registerBorrower(@RequestBody BorrowerRecord borrowerRecord) {
        registerService.registerBorrower(borrowerRecord.toEntity());
        return Resp.success(true);
    }

}